package com.samphanie.security.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

/**
 * @author ZSY
 * @email 1451691457@qq.com
 */
@Data
@With
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SecurityUser implements UserDetails, Serializable {
    private static final long serialVersionUID = 2107524072483774717L;

    private Long id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 用户密码
     */
    @JsonIgnore
    private String password;
    /**
     * 登录客户端ID
     */
    private String clientId;
    /**
     * 是否启用，默认启用
     */
    @Builder.Default
    private boolean enabled = true;
    /**
     * 账户是否未过期，默认未过期
     */
    @Builder.Default
    private boolean accountNonExpired = true;
    /**
     * 账户是否未锁定，默认未锁定
     */
    @Builder.Default
    private boolean accountNonLocked = true;
    /**
     * 密码是否未过期，默认未过期
     */
    @Builder.Default
    private boolean credentialsNonExpired = true;
    private Collection<SimpleGrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }
}
